package com.itqf.controller;

import com.itqf.entity.TbItem;
import com.itqf.entity.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/20
 * @Time: 下午4:25
 */
//@Controller
@RestController  //所有方法都响应json
//@Controller  + @ResponseBody  对象 -->json
//json--->java对象  @RequestBody
public class MyController1 {

    @RequestMapping("/findOne1")
    public TbItem findOne(){
        TbItem tbItem = new TbItem();
        tbItem.setId(1);
        tbItem.setPrice(1000);
        tbItem.setTitle("小米手机");

        return  tbItem;
    }

    @RequestMapping("/findAll1")  //Ambiguous mapping
    public List<TbItem> findAll(){
        List<TbItem> list = new ArrayList<>();
        for (int i = 1; i < 100; i++) {
            TbItem tbItem = new TbItem();
            tbItem.setId(i);
            tbItem.setPrice(1000+i);
            tbItem.setTitle("小米手机"+i);
            tbItem.setMoney(2378.8321+i);
            tbItem.setCreated(new Date());
            tbItem.setVersion(i);
            list.add(tbItem);

        }


        return  list;
    }


    @RequestMapping("/doLogin")
    public Map doLogin(@RequestBody User user){//json字符串--》java对象

        System.out.println(user);

        Map map  = new HashMap();
        map.put("code",0);
        map.put("msg","登录成功");
        return  map;

    }


}
